import $ from "jquery";
import ProfileMgr from "../../data/ProfileMgr";
class Header{
    constructor(){
        this.init.call(this);
    }
    init(){
        this.render();
        this.bindEvent();
    }
    render(){
        let html = ``;
        let cookie_user = ProfileMgr.getUserName();
        if(cookie_user){
            html += `<span>你好，</span>
            <a href="###">${cookie_user}</a>
            &nbsp;|&nbsp;
            <a class="logout" href="javascript:void(0)">退出</a>`;
        }
        else{
            html += `<a id="register" href="./register.html" target="_blank">
                <b>注册</b>
            </a>
            &nbsp;|&nbsp;
            <a id="login" href="./login.html">登录</a>`;
        }
        $("#loginusername").html(html);
    }
    bindEvent(){
        $(".logout").click(this.logout.bind(this));
    }
    logout(){
        ProfileMgr.setUserName("");
        location.reload();
    }
}
module.exports = Header;